package com.easy.controllor;

import com.easy.bean.Schedule;
import com.easy.bean.Train;
import com.easy.bean.TrainRoute;
import com.easy.mapper.ScheduleMapper;
import com.easy.service.ScheduleService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/schedule")
public class ScheduleControllor {

    @Autowired
    ScheduleService scheduleService;

    @PostMapping
    public Result add(@RequestBody Schedule schedule){
        Object obj = scheduleService.add(schedule);
        return Result.success(obj);
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable("id") Integer id){
        Object obj = scheduleService.del(id);
        return Result.success("删除成功",obj);
    }

    @PutMapping
    public Result edit(@RequestBody Schedule schedule){
        Object obj = scheduleService.edit( schedule);
        return Result.success(obj);
    }


    @GetMapping("/{id}")
    public Result one(@PathVariable("id") Integer id){
        Object obj = scheduleService.one(id);
        return Result.success(obj);
    }


    @GetMapping("/page")
    public Result page(Page page, Schedule schedule){
        //查询一共多少条数据
        //查询当前页要显示的数据
        //封装到page里面去
        scheduleService.page(page,schedule);
        //返回page对象
        return Result.success(page);
    }




}
